import java.util.Scanner;
import java.util.TreeSet;

public class Test02 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s;
        String a[];
        sc.nextLine();
        person p;
        TreeSet<person> ts = new TreeSet<person>();
        for (int i = 0; i < n; i++) {
            s = sc.nextLine();
            a = s.split(" ");
            p = new person(a[0],a[1]);
            ts.add(p);
        }
        for (person person : ts){
            System.out.println(person);
        }
    }
}

class person implements Comparable{
    String name;
    String id;
    int year, month, day;
    public person(String name,String id)
    {
        this.name = name;
        this.id = id;
        this.year = Integer.parseInt(id.substring(6,10));
        this.month = Integer.parseInt(id.substring(10,12));
        this.day = Integer.parseInt(id.substring(12,14));
    }

    public String toString()
    {
        return "{姓名=" + name +
                ", id='" + id +
                "'}";
    }

    @Override
    public int compareTo(Object o) {
        person p = (person) o;
        int i = this.year - p.year;
        if (i != 0){
            return i;
        }
        i = this.month - p.month;
        if (i != 0){
            return i;
        }
        return this.day - p.day;
    }
}
